const fs = require('fs');
const path = require( 'path' );

let pathname = __filename ;

let options = 'utf8';
// let options = { encoding: 'utf8' }

let callback = (error,content) => {
    if( error ) {
        console.log( error );
        return ;
    }
    console.log( content );
}

// https://nodejs.org/dist/latest-v16.x/docs/api/fs.html#fsreadfilepath-options-callback
// fs.readFile( pathname [ , options ] , callback ) 尝试读取指定文件的内容
let result = fs.readFile( pathname , options , callback );
console.log( result );

// 自行测试 readFileSync 函数
// https://nodejs.org/dist/latest-v16.x/docs/api/fs.html#fsreadfilesyncpath-options
// let x = fs.readFileSync(path[, options])